<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Object dan Array
 *
 * @package	CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author	Khoiruddin
 * @link	http://khoiruddin.com dan http://admin.anggit.com/blog/post/283/php-mengubah-object-ke-array-atau-sebaliknya.html diakses 30 Mei 2014 : 13:54 WIB
 */

if ( ! function_exists('object_dan_array'))
{
	function object2array($object) {
		$array = array();
		if (is_object($object)) $object = (array)$object;
		foreach($object as $k => $v) {
			if (is_object($v) || is_array($v)) $v = object2array($v);
			$array[$k] = $v;
		}
		return $array;
		// Contoh : $array = object2array($object);
	}
	
	function array2object($array) {
		$object = new stdClass();
		foreach($array as $k => $v) {
			if (is_array($v)) $v = array2object($v);
			$object->$k = $v;
		}
		return $object;
		// Contoh: $object = array2object($array);		
	}

}
